import request from "./request"
import querystring from 'query-string'

/** ============================================ 登录接口 =========================================== */
// 登录
export const reqLogin = (userInfo) => request({url: '/login', method: 'post', data: querystring.stringify(userInfo)})

// 注册
export const reqRegister = (registerInfo) => request({url: '/register', method: 'post', data: querystring.stringify(registerInfo)})

/** ======================================== 用户信息接口 =========================================== */
// 用户主页 _id用户id
export const reqGetUserhome = (ids) => request({url: '/home/user', method: 'get', params: ids})

// message页面顶部用户信息（头像 + 昵称）
export const reqMessagePageInfo = (_id) => request({url: '/tabbar/message/userinfo', method: 'get', params: _id})

// 图片上传接口
export const reqUploadUserPic = (form, _id) => request({url: '/upload/user', method: 'post', data: form, params: _id})

// 更新用户信息接口
export const reqUpdateUserInfo = (obj) => request({url: '/update/user', method: 'post', data: querystring.stringify(obj)})

/** ============================================= 搜索接口 ============================================= */
// 关键字搜索（联系人、群） keyword
export const reqSearch = (keyword) => request({url: '/search', method: 'get', params: keyword})

/** ============================================= 好友接口 ============================================= */
// 发送好友申请
// userId：自己id  friendId：对方id
export const reqAddFriend = (ids) => request({url: '/friend/add', method: 'post', data: querystring.stringify(ids)})

// 联系人页面获取好友列表
// userId：自己id
export const reqGetContactsFriendList = (userId) => request({url: '/contacts/friend', method: 'get', params: userId})

// 删除好友接口
// ids(obj) => userId：自己的id, friendId：好友id
export const reqDelFriend = (ids) => request({url: '/del/friend', method: 'get', params: ids})

// 获取当前用户未同意的好友申请列表
export const reqGetFriendNoAgree = (userId) => request({url: '/get/friend/noagree', method: 'get', params: userId})

// 通过好友申请接口
export const reqAgreeFriendApply = (ids) => request({url: '/friend/agree', method: 'post', data: querystring.stringify(ids)})


/** ============================================== 群接口 ============================================= */
// 新建群聊接口
export const reqCreateGroup = (info) => request({url: '/create/group', method: 'post', data: querystring.stringify(info)})

// 群头像上传接口
export const reqGroupPic = (form) => request({url: '/upload/group', method: 'post', data: form})

// 获取群主页信息
// ids => groupId 群id, userId 当前用户id
export const reqGetGroupHome = (ids) => request({url: '/home/group', method: 'get', params: ids})

// 获取群成员接口
// groupId 群id
export const reqGetGroupUserList = (groupId) => request({url: '/get/groupUser', method: 'get', params: groupId})

// 加入群聊（发送入群申请）
// ids(obj) => groupId, userId
export const reqAddGroup = (ids) => request({url: '/group/add', method: 'post', data: querystring.stringify(ids)})

// 联系人页面获取好友列表
// userId：用户id
export const reqGetContactsGroupList = (userId) => request({url: '/contacts/group', method: 'get', params: userId})

// 获取要编辑的群的信息
// ids(obj) => groupId（群id），groupLeaderId（群主id）
export const reqGetUpdateGroupInfo = (ids) => request({url: '/get/update/group', method: 'get', params: ids})

// 提交修改后的群信息
export const reqUpdateGroupInfo = (info) => request({url: '/update/groupInfo', method: 'post', data: querystring.stringify(info)})

// 删除群成员/群成员退群
// ids(obj) => groupId, userId
export const reqDelGroupUser = (ids) => request({url: '/del/groupUser', method: 'get', params: ids})

// 删除整个群
// groupId
export const reqDelGroup = (groupId) => request({url: '/del/group', method: 'get', params: groupId})

// 获取群申请信息列表
// 通过userId获取到群列表
export const reqGetGroupNoAgree = (userId) => request({url: '/get/group/noagree', method: 'get', params: userId})

// 通过用户入群申请
// ids => userId、groupId
export const reqAgreeGroupApply = (ids) => request({url: '/group/agree', method: 'post', data: querystring.stringify(ids)})

/** ========================================= 空间动态接口 ======================================== */
// 发布动态的图片上传接口
// 多图片
export const reqSpaceUploadPhotos = (form) => request({url: '/space/upload/photos', method: 'post', data: form})
// 单图片
export const reqSpaceUploadPhoto = (form) => request({url: '/space/upload/photo', method: 'post', data: form})

// 发布动态（新增）
export const reqAddSpace = (obj) => request({url: '/space/add', method: 'post', data: querystring.stringify(obj)})

// 获取空间动态列表
export const reqGetSpaceList = (userId) => request({url: '/space/get', method: 'get', params: userId})

// 删除动态接口
export const reqDelSpace = (_id) => request({url: '/space/del', method: 'get', params: _id})

// 用户空间动态详情接口
export const reqGetSpaceListDetails = (userId) => request({url: '/space/details', method: 'get', params: userId})

/** ========================================= 聊天接口 ======================================== */
// 获取当前聊天好友信息
export const reqGetFriendInfo = (info) => request({url: '/message/friend', method: 'get', params: info})

// 获取当前聊天群聊信息
export const reqGetGroupInfo = (info) => request({url: '/message/group', method: 'get', params: info})

// 私聊图片上传接口
// 单图片
export const reqPrivateUploadPhoto = (form) => request({url: '/chat/private/photo', method: 'post', data: form})
// 多图片
export const reqPrivateUploadPhotos = (form) => request({url: '/chat/private/photos', method: 'post', data: form})

// 群聊图片上传接口
// 单图片
export const reqGroupUploadPhoto = (form) => request({url: '/chat/group/photo', method: 'post', data: form})
// 多图片
export const reqGroupUploadPhotos = (form) => request({url: '/chat/group/photos', method: 'post', data: form})

// 获取tabar消息页的消息列表（前提是发送过消息的好友/群）
export const reqGetMessageList = (userId) => request({url: '/message/list', method: 'get', params: userId})

// 将好友聊天记录状态设置为已读
export const reqSetMessageRead = (ids) => request({url: '/message/read', method: 'get', params: ids})